//
//  MBDRouter.swift
//  MasterBoy
//
//  Created by kyson on 2023/10/20.
//

import Foundation

import JLRoutes


class MBDRouter : NSObject {
    
    static let shared = MBDRouter()
    
    func registeRouter() -> Void {
        
        JLRoutes.global().addRoute("uploadGroup", handler : { _ in NSDictionary.self
            let vc = MBDUploadGroupViewController(viewModel: MBDUploadGroupViewModel())
            
            if let topController = UIApplication.topViewController() {
                topController.navigationController?.pushViewController(vc, animated: true)
            }
            
            return true
        })
        
        JLRoutes.global().addRoute("personalInfo", handler : { _ in NSDictionary.self
            if(MBDUserCenter.shared.userInfoFetched) {
                let vc = MBDPersonalInfoViewController()
                
                if let topController = UIApplication.topViewController() {
                    topController.navigationController?.pushViewController(vc, animated: true)
                }
                
            } else {
                
                if let topController = UIApplication.topViewController() {
                    topController.showDetailViewController(MBDLoginViewController(), sender: nil)
                }
                
            }
            
            return true
        })
        
        JLRoutes.global().addRoute("userInfo", handler : { params in
            let vm = MBDUserInfoViewModel(params: params)
            let vc = MBDUserInfoViewController()
            vc.viewModel = vm
            
            if let topController = UIApplication.topViewController() {
                topController.navigationController?.pushViewController(vc, animated: true)
            }
            
            return true
        })
        
        
        
        JLRoutes.global().addRoute("postList", handler : { _ in NSDictionary.self
            if(MBDUserCenter.shared.userInfoFetched) {
                let vc = MBDPostListViewController()
                
                if let topController = UIApplication.topViewController() {
                    topController.navigationController?.pushViewController(vc, animated: true)
                }
                
                
            } else {
                if let topController = UIApplication.topViewController() {
                    topController.showDetailViewController(MBDLoginViewController(), sender: nil)
                }
            }
            
            return true
        })
        
        JLRoutes.global().addRoute("integrate", handler : { _ in NSDictionary.self
            if(MBDUserCenter.shared.userInfoFetched) {
                let vc = MBDMyIntegrationViewController()
                
                if let topController = UIApplication.topViewController() {
                    topController.navigationController?.pushViewController(vc, animated: true)
                }
                
            } else {
                
                if let topController = UIApplication.topViewController() {
                    topController.showDetailViewController(MBDLoginViewController(), sender: nil)
                }
                
            }
            
            return true
        })
        
        JLRoutes.global().addRoute("setting", handler : { _ in NSDictionary.self
            let vc = MBDSettingViewController()
            
            if let topController = UIApplication.topViewController() {
                topController.navigationController?.pushViewController(vc, animated: true)
            }
            
            
            return true
        })
        
    }

}
